home *** CD-ROM | disk | FTP | other *** search
/ Venus 7000 / darktronics.iso / Software / Service Packs / Win2kSP4.exe / i386 / certsrck.in_ / certsrck.inc
Encoding:
Text File  |  2003-06-19  |  5.1 KB  |  190 lines

  1. <%' CODEPAGE=65001 'UTF-8%>
  2. <%' certsrck.inc - (CERT)srv web - (S)cript: (R)equest-(C)ooc(K)ie management
  3.   ' Copyright (C) Microsoft Corporation, 1998 - 1999 %>
  4. <%
  5.     ' Format of our cookie:
  6.     ' '[' <ReqID> ',' <TargetStoreFlags> ',' <SaveCert> ',' <FriendlyType> ']'...
  7.     Const FIELD_REQID=0
  8.     Const FIELD_TARGETSTOREFLAGS=1
  9.     Const FIELD_SAVECERT=2
  10.     Const FIELD_FRIENDLYTYPE=3
  11.     Const NUM_FIELDS=4
  12.     Const REQUEST_COOKIE_NAME="Requests"
  13.  
  14.     ' Look up the requests in the cookie, and return an array of 'request' arrays
  15.     Function GetRequests(bEncodeRequests)
  16.  
  17.         ' Get the cookie
  18.         Dim sRequests
  19.         sRequests=Request.Cookies(REQUEST_COOKIE_NAME)
  20.  
  21.         ' If the cookie was never set, return an empty array
  22.         If ""=sRequests Then
  23.             GetRequests=Null
  24.             Exit Function
  25.         End If
  26.  
  27.         ' If we requested that the requests be encoded, do so now:
  28.         If True=bEncodeRequests Then
  29.             sRequests = Server.HTMLEncode(sRequests)
  30.         End If    
  31.  
  32.         Dim nRequests
  33.         Dim rgRequests()
  34.         nRequests=0
  35.  
  36.         ' Loop through all the requests in the string
  37.         Dim nSplitIndex
  38.         Do
  39.             ' Find the next request
  40.             nSplitIndex=InStr(sRequests,"]")
  41.             If 0=nSplitIndex Then
  42.                 Exit Do
  43.             End If
  44.  
  45.             ' Split this Request off the string
  46.             Dim sElem
  47.             sElem=Mid(sRequests, 2, nSplitIndex-2)
  48.             sRequests=Mid(sRequests, nSplitIndex+1)
  49.  
  50.             ' Spit this request apart
  51.             Dim rgElem
  52.             rgElem=Split(sElem, ",")
  53.  
  54.             ' Safety check
  55.             If NUM_FIELDS-1<>UBound(rgElem) Then
  56.                 ' Cookie is corrupt
  57.                 nRequests=0
  58.                 Exit Do
  59.             End If
  60.  
  61.             ' Add this array to our array of requests
  62.             ReDim Preserve rgRequests(nRequests)
  63.             rgRequests(nRequests)=rgElem
  64.             nRequests=nRequests+1
  65.  
  66.             ' safety check for testing
  67.             'If nRequests>25 Then
  68.             '    Err.Raise 6
  69.             'End If
  70.  
  71.         Loop ' End string-parsing loop
  72.     
  73.         ' if there was an error parsing the cookie, just assume it was empty.
  74.         If 0=nRequests Then
  75.             GetRequests=Null
  76.         Else
  77.             GetRequests=rgRequests
  78.         End If
  79.  
  80.     End Function
  81.  
  82.     ' Combine a requests-array into a single string and set it as a cookie
  83.     Sub PutRequests(rgRequests)
  84.         Dim sCookie, sRequests, nIndex
  85.         sRequests=""
  86.  
  87.         ' check for the empty list
  88.         If IsNull(rgRequests) Then
  89.             ' the list is empty
  90.             '   do nothing
  91.             sRequests="-" ' Lynx won't set an empty cookie, so set an invalid one
  92.         Else
  93.             ' the list is not empty
  94.             ' build a string for each request and concatenate to make cookie
  95.             For nIndex=0 To UBound(rgRequests)
  96.                 sRequests=sRequests & "[" & _
  97.                     rgRequests(nIndex)(FIELD_REQID) & "," & _
  98.                     rgRequests(nIndex)(FIELD_TARGETSTOREFLAGS) & "," & _
  99.                     rgRequests(nIndex)(FIELD_SAVECERT) & "," & _
  100.                     rgRequests(nIndex)(FIELD_FRIENDLYTYPE) & "]"
  101.             Next
  102.         End If
  103.  
  104.         ' Set the cookie
  105.         Response.Cookies(REQUEST_COOKIE_NAME)=sRequests
  106.  
  107.         ' Set the expiration date
  108.         Response.Cookies(REQUEST_COOKIE_NAME).Expires=Now+nPendingTimeoutDays
  109.  
  110.         ' Set the path
  111.         Response.Cookies(REQUEST_COOKIE_NAME).Path="/certsrv"
  112.  
  113.     End Sub
  114.  
  115.     ' Remove a given request from the requests cookie
  116.     Sub RemoveReq(nReqID)
  117.         ' get the array of requests
  118.         Dim rgRequests
  119.         rgRequests=GetRequests(False)
  120.  
  121.         ' if the cookie is empty, just ignore
  122.         If IsNull(rgRequests) Then
  123.             Exit Sub
  124.         End If
  125.  
  126.         ' find the request
  127.         Dim nIndex
  128.         Dim nFoundIndex
  129.         nFoundIndex=-1
  130.         For nIndex=0 To UBound(rgRequests)
  131.             If nReqID=rgRequests(nIndex)(FIELD_REQID) Then
  132.                 nFoundIndex=nIndex
  133.                 Exit For
  134.             End If
  135.         Next
  136.  
  137.         If -1=nFoundIndex Then
  138.             ' request not found, probably a reload and it was deleted already
  139.             '   do nothing
  140.         Else
  141.             ' remove the request:
  142.             If 0=UBound(rgRequests) Then
  143.                 ' this is the last request
  144.                 ' removing it leaves an empty list
  145.                 rgRequests=Null
  146.             Else
  147.                 ' Not the last request, so shuffle down
  148.                 ' (this is not the most efficient, but it keeps the requests in order)
  149.                 For nIndex=nFoundIndex To UBound(rgRequests)-1
  150.                     rgRequests(nIndex)=rgRequests(nIndex+1)
  151.                 Next
  152.  
  153.                 ' shrink the array
  154.                 ReDim Preserve rgRequests(UBound(rgRequests)-1)
  155.             End If
  156.  
  157.             ' set the cookie
  158.             PutRequests rgRequests
  159.         End If
  160.     End Sub
  161.  
  162.     ' Add the current request to the request cookie
  163.     Sub AddRequest
  164.         ' build a request object for this request
  165.         Dim rgNewReq(3) 'NUM_FIELDS-1
  166.         rgNewReq(FIELD_REQID)=ICertRequest.GetRequestId()
  167.         rgNewReq(FIELD_TARGETSTOREFLAGS)=Request.Form("TargetStoreFlags")
  168.         rgNewReq(FIELD_SAVECERT)=Request.Form("SaveCert")
  169.         rgNewReq(FIELD_FRIENDLYTYPE)=Request.Form("FriendlyType")
  170.  
  171.         ' prevent special split characters from being placed in the string
  172.         ' by converting them to spaces
  173.         rgNewReq(FIELD_FRIENDLYTYPE)=Replace(rgNewReq(FIELD_FRIENDLYTYPE), ",", " ")
  174.         rgNewReq(FIELD_FRIENDLYTYPE)=Replace(rgNewReq(FIELD_FRIENDLYTYPE), "]", " ")
  175.  
  176.         ' add it to the list
  177.         Dim rgRequests
  178.         rgRequests=GetRequests(False)
  179.         If IsNull(rgRequests) Then 
  180.             ' cookie has never been set
  181.             ReDim rgRequests(0)
  182.         Else
  183.             ' save old requests in cookie
  184.             ReDim Preserve rgRequests(UBound(rgRequests)+1)
  185.         End If
  186.         rgRequests(UBound(rgRequests))=rgNewReq
  187.         PutRequests rgRequests
  188.     End Sub
  189. %>
  190.